//
//  SRWorkListTableViewCell.m
//  StoryShow
//
//  Created by CyonLeuMBP on 2017/6/7.
//  Copyright © 2017年 qudiandu.cn. All rights reserved.
//

#import "SRWorkListTableViewCell.h"
#import <NSDate+DateToDisplayString.h>

NSString *const kSRWorkListTableViewCell = @"SRWorkListTableViewCell";

@interface SRWorkListTableViewCell ()

@property (weak, nonatomic) IBOutlet UIView *borderView;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *lessonLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *scoreImageView;
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
@property (weak, nonatomic) IBOutlet UIView *coverView;
@property (weak, nonatomic) IBOutlet UIButton *deleteButton;

@property (strong, nonatomic) SRWorkListItemModel *model;

@end

@implementation SRWorkListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    FZStyleSheet *css = [FZStyleSheet currentStyleSheet];
    
    self.lessonLabel.textColor = css.color_1;
    self.lessonLabel.font = css.fontOfH3;
    
    self.descLabel.textColor = css.color_1;
    self.descLabel.font = css.fontOfH5;
    
    self.timeLabel.textColor = css.color_1;
    self.timeLabel.font = css.fontOfH7;
    
    self.scoreLabel.textColor = css.color_4;
    self.scoreLabel.font = css.fontOfH5;
    
    self.borderView.clipsToBounds = YES;
    self.borderView.layer.cornerRadius = 5;
    self.borderView.backgroundColor = css.color_5;
    
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.coverView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)updateCellInfo:(SRWorkListItemModel *)model {
    if (!model) {
        return;
    }
    
    self.model = model;
    self.lessonLabel.text = model.title;
    self.descLabel.text = model.unit;
    
    NSInteger score = [model.score integerValue];
    if (score > 0) {
        self.scoreImageView.hidden = NO;
        self.scoreLabel.hidden = NO;
        self.scoreLabel.text = [NSString stringWithFormat:@"%ld", (long)[model.score integerValue] ];
        if (score > 60) {
            self.scoreImageView.image = [UIImage imageNamed:@"pass"];
        } else {
            self.scoreImageView.image = [UIImage imageNamed:@"unpass"];
        }
    } else {
        self.scoreImageView.hidden = NO;
        self.scoreLabel.hidden = NO;
    }
    
    
    [self.iconImageView fz_setImageWithDefaultPlaceholderWithURL:[NSURL URLWithString:model.page_url] placeholderSize:CGSizeZero];
    
    self.timeLabel.text = [NSDate dateToDetailDisplayStringForTimeInterval:[model.create_time longLongValue]];
    
    
    
}

- (void)setIsEditStatus:(BOOL)isEditStatus {
    _isEditStatus = isEditStatus;
    
    self.coverView.hidden = !isEditStatus;
    self.deleteButton.hidden = !isEditStatus;
}

- (IBAction)onDeleteButton:(id)sender {
    if (self.touchDeleteButtonBlock) {
        self.touchDeleteButtonBlock(self.model);
    }
}

@end
